Closes #653
authorPaul Woolcock <pwoolcoc@gmail.com>
Tue, 21 Oct 2014 18:48:16 +0000 (14:48 -0400)
committerPaul Woolcock <paul@woolcock.us>
Wed, 1 Jul 2015 11:27:01 +0000 (07:27 -0400)
Adds a `-q|--quiet` option to all cargo commands that suppresses output from
cargo. In the case of `cargo run`, output from the project executable will
still be shown.

26 files changed:
src/bin/bench.rs
src/bin/build.rs
src/bin/cargo.rs
src/bin/clean.rs
src/bin/doc.rs
src/bin/fetch.rs
src/bin/generate_lockfile.rs
src/bin/git_checkout.rs
src/bin/login.rs
src/bin/new.rs
src/bin/owner.rs
src/bin/package.rs
src/bin/pkgid.rs
src/bin/publish.rs
src/bin/run.rs
src/bin/rustc.rs
src/bin/search.rs
src/bin/test.rs
src/bin/update.rs
src/bin/verify_project.rs
src/bin/yank.rs
src/cargo/core/mod.rs
src/cargo/core/shell.rs
src/cargo/lib.rs
tests/test_cargo_run.rs
tests/test_shell.rs

index ecc8fd68636478005ce14aa5ae791bb74f4a2b78..4b9d5164aef1b18b0574a3997ef387f5522a03cd 100644 (file)
@@ -12,6 +12,7 @@ struct Options {
     flag_target: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_lib: bool,
     flag_bin: Vec<String>,
     flag_example: Vec<String>,
@@ -41,6 +42,7 @@ Options:
     --target TRIPLE          Build for the target triple
     --manifest-path PATH     Path to the manifest to build benchmarks for
     -v, --verbose            Use verbose output
+    -q, --quiet              No output printed to stdout
 
 All of the trailing arguments are passed to the benchmark binaries generated
 for filtering benchmarks and generally providing options configuring how they
@@ -59,7 +61,7 @@ Compilation can be customized with the `bench` profile in the manifest.
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
 
     let ops = ops::TestOptions {
         no_run: options.flag_no_run,
index 3af175ec1b48c1c59f71e2adec221c5581aee332..0ba089e1bb211cae24c27e9708610c0c6bf4e6bd 100644 (file)
@@ -14,6 +14,7 @@ struct Options {
     flag_target: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_release: bool,
     flag_lib: bool,
     flag_bin: Vec<String>,
@@ -43,6 +44,7 @@ Options:
     --target TRIPLE          Build for the target triple
     --manifest-path PATH     Path to the manifest to compile
     -v, --verbose            Use verbose output
+    -q, --quiet              No output printed to stdout
 
 If the --package argument is given, then SPEC is a package id specification
 which indicates which package should be built. If it is not given, then the
@@ -57,7 +59,7 @@ the --release flag will use the `release` profile instead.
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     debug!("executing; cmd=cargo-build; args={:?}",
            env::args().collect::<Vec<_>>());
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
 
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 
index 0e5318b4947af9e3a35cbadff9225dc5353e6505..73646756d3171195059cb80cfb6945bcbb5d6f1e 100644 (file)
@@ -20,6 +20,7 @@ use cargo::util::{CliError, CliResult, lev_distance, Config};
 struct Flags {
     flag_list: bool,
     flag_verbose: bool,
+    flag_quiet: bool,
     arg_command: String,
     arg_args: Vec<String>,
 }
@@ -36,6 +37,7 @@ Options:
     -V, --version    Print version info and exit
     --list           List installed commands
     -v, --verbose    Use verbose output
+    -q, --quiet             No output printed to stdout
 
 Some common cargo commands are:
     build       Compile the current project
@@ -89,7 +91,7 @@ macro_rules! each_subcommand{ ($mac:ident) => ({
   on this top-level information.
 */
 fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(flags.flag_verbose);
+    try!(config.shell().set_verbosity(flags.flag_verbose, flags.flag_quiet));
 
     init_git_transports(config);
 
index cc66f29fdcf53cebd391ebe08c17490168bd4174..825d05c713d4da6103a03a8613ddd8eddbd1d21e 100644 (file)
@@ -10,6 +10,7 @@ struct Options {
     flag_target: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -24,6 +25,7 @@ Options:
     --manifest-path PATH     Path to the manifest to the package to clean
     --target TRIPLE          Target triple to clean output for (default all)
     -v, --verbose            Use verbose output
+    -q, --quiet              No output printed to stdout
 
 If the --package argument is given, then SPEC is a package id specification
 which indicates which package's artifacts should be cleaned out. If it is not
@@ -32,7 +34,7 @@ and its format, see the `cargo help pkgid` command.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
 
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
index bd1127e2fe5168aa1b831122f1da013c20ab62f4..157f3f3930764fb3952df849792e2d2a692fd34e 100644 (file)
@@ -12,6 +12,7 @@ struct Options {
     flag_no_deps: bool,
     flag_open: bool,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_package: Option<String>,
 }
 
@@ -32,6 +33,7 @@ Options:
     --target TRIPLE          Build for the target triple
     --manifest-path PATH     Path to the manifest to document
     -v, --verbose            Use verbose output
+    -q, --quiet              No output printed to stdout
 
 By default the documentation for the local package and all dependencies is
 built. The output is all placed in `target/doc` in rustdoc's usual format.
@@ -43,7 +45,7 @@ the `cargo help pkgid` command.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
 
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 
index a5afbf239d5a4233afb2e122ab2ef4dd89e5fb78..3c8ecbdc476725513a2869441a747ffe1c048c67 100644 (file)
@@ -6,6 +6,7 @@ use cargo::util::important_paths::find_root_manifest_for_cwd;
 struct Options {
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -18,6 +19,7 @@ Options:
     -h, --help              Print this message
     --manifest-path PATH    Path to the manifest to fetch dependencies for
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 If a lockfile is available, this command will ensure that all of the git
 dependencies and/or registries dependencies are downloaded and locally
@@ -30,7 +32,7 @@ all updated.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
     try!(ops::fetch(&root, config).map_err(|e| {
         CliError::from_boxed(e, 101)
index d9777ef663a852a7bb4bbce6acaeb2517468d1b0..bb2ade5fef9108dfa1a88e541ee2fa4bf98dd2e5 100644 (file)
@@ -8,6 +8,7 @@ use cargo::util::important_paths::find_root_manifest_for_cwd;
 struct Options {
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -20,11 +21,12 @@ Options:
     -h, --help              Print this message
     --manifest-path PATH    Path to the manifest to generate a lockfile for
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 
     ops::generate_lockfile(&root, config)
index 43f62c81d5abe4c89a2a06667646696b805686f0..eaf1df3671d4244940c1c410acc7d988f56097ab 100644 (file)
@@ -7,6 +7,7 @@ struct Options {
     flag_url: String,
     flag_reference: String,
     flag_verbose: bool,
+    flag_quiet: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -17,10 +18,11 @@ Usage:
 Options:
     -h, --help              Print this message
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let Options { flag_url: url, flag_reference: reference, .. } = options;
 
     let url = try!(url.to_url().map_err(|e| {
index 16c8f7c85ccb5ca3d009bebb82b56097545a7fa3..a0ec4bfea83a6274880fc819d8ccf8513c9f6b3d 100644 (file)
@@ -11,6 +11,7 @@ struct Options {
     flag_host: Option<String>,
     arg_token: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -23,11 +24,12 @@ Options:
     -h, --help              Print this message
     --host HOST             Host to set the token for
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let token = match options.arg_token.clone() {
         Some(token) => token,
         None => {
index fdfb0283e0c1ac149596cfbdfcd7a49806b459a7..6c1b6598cef1210ab607c0b1d1afad5cd2ba3990 100644 (file)
@@ -6,6 +6,7 @@ use cargo::util::{CliResult, CliError, Config};
 #[derive(RustcDecodable)]
 struct Options {
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_bin: bool,
     arg_path: String,
     flag_name: Option<String>,
@@ -27,11 +28,12 @@ Options:
     --bin               Use a binary instead of a library template
     --name <name>       Set the resulting package name
     -v, --verbose       Use verbose output
+    -q, --quiet         No output printed to stdout
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::<Vec<_>>());
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
 
     let Options { flag_bin, arg_path, flag_name, flag_vcs, .. } = options;
 
index 38edea893fa62bbbb524ce4075e804cac042767a..598555a9a5b6905461408e242d59edb822af0442 100644 (file)
@@ -9,6 +9,7 @@ struct Options {
     flag_remove: Option<Vec<String>>,
     flag_index: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_list: bool,
 }
 
@@ -26,6 +27,7 @@ Options:
     --index INDEX           Registry index to modify owners for
     --token TOKEN           API token to use when authenticating
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 This command will modify the owners for a package on the specified registry (or
 default). Note that owners of a package can upload new versions, yank old
@@ -33,7 +35,7 @@ versions, and also modify the set of owners, so take caution!
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let opts = ops::OwnersOptions {
         krate: options.arg_crate,
         token: options.flag_token,
index 444b114fbb3113fa807c1f454b6f148d51fe70d5..828fac3cce2ac4753492fa03779ea34d30e68e96 100644 (file)
@@ -5,6 +5,7 @@ use cargo::util::important_paths::find_root_manifest_for_cwd;
 #[derive(RustcDecodable)]
 struct Options {
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_manifest_path: Option<String>,
     flag_no_verify: bool,
     flag_no_metadata: bool,
@@ -24,11 +25,12 @@ Options:
     --no-metadata           Ignore warnings about a lack of human-usable metadata
     --manifest-path PATH    Path to the manifest to compile
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
     ops::package(&root, config,
                  !options.flag_no_verify,
index c5fe8de37d960dbba78d189eb4e963b4248c74ba..400719e77ec731b8fd058d9e43dfc93d369afec6 100644 (file)
@@ -5,6 +5,7 @@ use cargo::util::important_paths::{find_root_manifest_for_cwd};
 #[derive(RustcDecodable)]
 struct Options {
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_manifest_path: Option<String>,
     arg_spec: Option<String>,
 }
@@ -19,6 +20,7 @@ Options:
     -h, --help              Print this message
     --manifest-path PATH    Path to the manifest to the package to clean
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 Given a <spec> argument, print out the fully qualified package id specifier.
 This command will generate an error if <spec> is ambiguous as to which package
@@ -43,7 +45,7 @@ Example Package IDs
 
 pub fn execute(options: Options,
                config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path.clone()));
 
     let spec = options.arg_spec.as_ref().map(|s| &s[..]);
index 224c9a8b656927f9e21e11b544420b8329fadf32..478947b441b9128f45dcc3cc5c845379593567ce 100644 (file)
@@ -8,6 +8,7 @@ struct Options {
     flag_token: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_no_verify: bool,
 }
 
@@ -24,11 +25,12 @@ Options:
     --no-verify             Don't verify package tarball before publish
     --manifest-path PATH    Path to the manifest to compile
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let Options {
         flag_token: token,
         flag_host: host,
index c34c36be1b47ed11de2a687d4b046972a7da5af2..dbc0b90ca5486fe10dccfee90da21b9433ef95a8 100644 (file)
@@ -12,6 +12,7 @@ struct Options {
     flag_target: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_release: bool,
     arg_args: Vec<String>,
 }
@@ -33,6 +34,7 @@ Options:
     --target TRIPLE         Build for the target triple
     --manifest-path PATH    Path to the manifest to execute
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 If neither `--bin` or `--example` are given, then if the project only has one
 bin target it will be run. Otherwise `--bin` specifies the bin target to run,
@@ -43,7 +45,8 @@ All of the trailing arguments are passed as to the binary to run.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
+
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 
     let (mut examples, mut bins) = (Vec::new(), Vec::new());
index f91c7d89c13f75bf238adac0ce4ab41815cb360d..ddfca47518ce097c934b666040eca90e2bd096ad 100644 (file)
@@ -15,6 +15,7 @@ struct Options {
     flag_target: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_release: bool,
     flag_lib: bool,
     flag_bin: Vec<String>,
@@ -44,6 +45,7 @@ Options:
     --target TRIPLE          Target triple which compiles will be for
     --manifest-path PATH     Path to the manifest to fetch depednencies for
     -v, --verbose            Use verbose output
+    -q, --quiet              No output printed to stdout
 
 The specified target for the current package (or package specified by SPEC if
 provided) will be compiled along with all of its dependencies. The specified
@@ -60,7 +62,7 @@ must be used to select which target is compiled.
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     debug!("executing; cmd=cargo-rustc; args={:?}",
            env::args().collect::<Vec<_>>());
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
 
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 
index ee638cc5d6f3368b3c7049d69b1a45c9a475354b..8710f546da45c13a864261e2c03631e953d22e25 100644 (file)
@@ -5,6 +5,7 @@ use cargo::util::{CliResult, CliError, Config};
 struct Options {
     flag_host: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     arg_query: String
 }
 
@@ -19,10 +20,11 @@ Options:
     -h, --help              Print this message
     --host HOST             Host of a registry to search in
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let Options {
         flag_host: host,
         arg_query: query,
index 03ce558cff2272c89f6f1ad8f919ad5bdd0ab337..aafa8ec1cb22f8c4e70cfdcd8bc8047687b30833 100644 (file)
@@ -18,6 +18,7 @@ struct Options {
     flag_test: Vec<String>,
     flag_bench: Vec<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_release: bool,
 }
 
@@ -43,6 +44,7 @@ Options:
     --target TRIPLE          Build for the target triple
     --manifest-path PATH     Path to the manifest to build tests for
     -v, --verbose            Use verbose output
+    -q, --quiet              No output printed to stdout
 
 All of the trailing arguments are passed to the test binaries generated for
 filtering tests and generally providing options configuring how they run. For
@@ -63,7 +65,7 @@ Compilation can be configured via the `test` profile in the manifest.
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
 
     let ops = ops::TestOptions {
         no_run: options.flag_no_run,
index 61df563d30b2a09d0c920b5945bd3a29f88119a2..f1956566bf1c95e32cbaac124c276c0d894f7ee2 100644 (file)
@@ -11,6 +11,7 @@ struct Options {
     flag_precise: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -26,6 +27,7 @@ Options:
     --precise PRECISE        Update a single dependency to exactly PRECISE
     --manifest-path PATH     Path to the manifest to compile
     -v, --verbose            Use verbose output
+    -q, --quiet              No output printed to stdout
 
 This command requires that a `Cargo.lock` already exists as generated by
 `cargo build` or related commands.
@@ -50,7 +52,7 @@ For more information about package id specifications, see `cargo help pkgid`.
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 
     let spec = options.flag_package.as_ref();
index 076cfc2db6a7c9506a842f517f4743e22fc9fd58..5b72f06678e5b6d97add80cb39973a95d4e8ea6c 100644 (file)
@@ -13,6 +13,7 @@ pub type Error = HashMap<String, String>;
 struct Flags {
     flag_manifest_path: String,
     flag_verbose: bool,
+    flag_quiet: bool,
 }
 
 pub const USAGE: &'static str = "
@@ -24,10 +25,11 @@ Options:
     -h, --help              Print this message
     --manifest-path PATH    Path to the manifest to verify
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 ";
 
 pub fn execute(args: Flags, config: &Config) -> CliResult<Option<Error>> {
-    config.shell().set_verbose(args.flag_verbose);
+    try!(config.shell().set_verbosity(args.flag_verbose, args.flag_quiet));
 
     let mut contents = String::new();
     let file = File::open(&args.flag_manifest_path);
index 90cf677f104a6d5d843900b7e1f42bee1a7fcdf4..efd2032618e2b7852520d0a55252c1f62fb22328 100644 (file)
@@ -8,6 +8,7 @@ struct Options {
     flag_vers: Option<String>,
     flag_index: Option<String>,
     flag_verbose: bool,
+    flag_quiet: bool,
     flag_undo: bool,
 }
 
@@ -24,6 +25,7 @@ Options:
     --index INDEX           Registry index to yank from
     --token TOKEN           API token to use when authenticating
     -v, --verbose           Use verbose output
+    -q, --quiet             No output printed to stdout
 
 The yank command removes a previously pushed crate's version from the server's
 index. This command does not delete any data, and the crate will still be
@@ -35,7 +37,7 @@ crates to be locked to any yanked version.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    config.shell().set_verbose(options.flag_verbose);
+    try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(ops::yank(config,
                    options.arg_crate,
                    options.flag_vers,
index cfd3aebdfd0ad579463632ed112ed3808be0b595..f468f8c79c7499a1ee08f6731ef2772ab8e6c8a9 100644 (file)
@@ -5,7 +5,7 @@ pub use self::package_id::{PackageId, Metadata};
 pub use self::package_id_spec::PackageIdSpec;
 pub use self::registry::Registry;
 pub use self::resolver::Resolve;
-pub use self::shell::{Shell, MultiShell, ShellConfig};
+pub use self::shell::{Shell, MultiShell, ShellConfig, Verbosity};
 pub use self::source::{Source, SourceId, SourceMap, SourceSet, GitReference};
 pub use self::summary::Summary;
 
index e6e3f49b2deec5a997a203732e4d24c26b48f984..ff5edba1045cc23fe34278887bb084525d8fedc9 100644 (file)
@@ -7,11 +7,21 @@ use term::color::{Color, BLACK, RED, GREEN, YELLOW};
 use term::{Terminal, TerminfoTerminal, color};
 
 use self::AdequateTerminal::{NoColor, Colored};
+use self::Verbosity::{Verbose, Normal, Quiet};
+
+use util::errors::{human, CargoResult};
+
+#[derive(Clone, Copy, PartialEq)]
+pub enum Verbosity {
+    Verbose,
+    Normal,
+    Quiet
+}
 
 #[derive(Clone, Copy)]
 pub struct ShellConfig {
     pub color: bool,
-    pub verbose: bool,
+    pub verbosity: Verbosity,
     pub tty: bool
 }
 
@@ -28,12 +38,12 @@ pub struct Shell {
 pub struct MultiShell {
     out: Shell,
     err: Shell,
-    verbose: bool
+    verbosity: Verbosity
 }
 
 impl MultiShell {
-    pub fn new(out: Shell, err: Shell, verbose: bool) -> MultiShell {
-        MultiShell { out: out, err: err, verbose: verbose }
+    pub fn new(out: Shell, err: Shell, verbosity: Verbosity) -> MultiShell {
+        MultiShell { out: out, err: err, verbosity: verbosity }
     }
 
     pub fn out(&mut self) -> &mut Shell {
@@ -45,27 +55,37 @@ impl MultiShell {
     }
 
     pub fn say<T: ToString>(&mut self, message: T, color: Color) -> io::Result<()> {
-        self.out().say(message, color)
+        match self.verbosity {
+            Quiet => Ok(()),
+            _ => self.out().say(message, color)
+        }
     }
 
     pub fn status<T, U>(&mut self, status: T, message: U) -> io::Result<()>
         where T: fmt::Display, U: fmt::Display
     {
-        self.out().say_status(status, message, GREEN)
+        match self.verbosity {
+            Quiet => Ok(()),
+            _ => self.out().say_status(status, message, GREEN)
+        }
     }
 
     pub fn verbose<F>(&mut self, mut callback: F) -> io::Result<()>
         where F: FnMut(&mut MultiShell) -> io::Result<()>
     {
-        if self.verbose { return callback(self) }
-        Ok(())
+        match self.verbosity {
+            Verbose => return callback(self),
+            _ => Ok(())
+        }
     }
 
     pub fn concise<F>(&mut self, mut callback: F) -> io::Result<()>
         where F: FnMut(&mut MultiShell) -> io::Result<()>
     {
-        if !self.verbose { return callback(self) }
-        Ok(())
+        match self.verbosity {
+            Verbose => Ok(()),
+            _ => return callback(self)
+        }
     }
 
     pub fn error<T: ToString>(&mut self, message: T) -> io::Result<()> {
@@ -76,12 +96,27 @@ impl MultiShell {
         self.err().say(message, YELLOW)
     }
 
+    pub fn set_verbosity(&mut self, verbose: bool, quiet: bool) -> CargoResult<()> {
+        self.verbosity = match (verbose, quiet) {
+            (true, true) => return Err(human("cannot set both --verbose and --quiet")),
+            (true, false) => Verbose,
+            (false, true) => Quiet,
+            (false, false) => Normal
+        };
+        Ok(())
+    }
+
+    /// shortcut for commands that don't have both --verbose and --quiet
     pub fn set_verbose(&mut self, verbose: bool) {
-        self.verbose = verbose;
+        if verbose {
+            self.verbosity = Verbose;
+        } else {
+            self.verbosity = Normal;
+        }
     }
 
-    pub fn get_verbose(&self) -> bool {
-        self.verbose
+    pub fn get_verbose(&self) -> Verbosity {
+        self.verbosity
     }
 }
 
@@ -103,24 +138,33 @@ impl Shell {
     pub fn verbose<F>(&mut self, mut callback: F) -> io::Result<()>
         where F: FnMut(&mut Shell) -> io::Result<()>
     {
-        if self.config.verbose { return callback(self) }
-        Ok(())
+        match self.config.verbosity {
+            Verbose => return callback(self),
+            _ => Ok(())
+        }
     }
 
     pub fn concise<F>(&mut self, mut callback: F) -> io::Result<()>
         where F: FnMut(&mut Shell) -> io::Result<()>
     {
-        if !self.config.verbose { return callback(self) }
-        Ok(())
+        match self.config.verbosity {
+            Verbose => Ok(()),
+            _ => return callback(self)
+        }
     }
 
     pub fn say<T: ToString>(&mut self, message: T, color: Color) -> io::Result<()> {
-        try!(self.reset());
-        if color != BLACK { try!(self.fg(color)); }
-        try!(write!(self, "{}\n", message.to_string()));
-        try!(self.reset());
-        try!(self.flush());
-        Ok(())
+        match self.config.verbosity {
+            Quiet => Ok(()),
+            _ => {
+                try!(self.reset());
+                if color != BLACK { try!(self.fg(color)); }
+                try!(write!(self, "{}\n", message.to_string()));
+                try!(self.reset());
+                try!(self.flush());
+                Ok(())
+            },
+        }
     }
 
     pub fn say_status<T, U>(&mut self, status: T, message: U, color: Color)
index fde0b9bc28748f7a1439e6568043dff34d7c95e6..33c83add0ba5fd7618d91aac582bd66d9bd6ab28 100644 (file)
@@ -31,7 +31,8 @@ use rustc_serialize::{Decodable, Encodable};
 use rustc_serialize::json::{self, Json};
 use docopt::Docopt;
 
-use core::{Shell, MultiShell, ShellConfig};
+use core::{Shell, MultiShell, ShellConfig, Verbosity};
+use core::shell::Verbosity::{Verbose};
 use term::color::{BLACK, RED};
 
 pub use util::{CargoError, CliError, CliResult, human, Config, ChainError};
@@ -95,7 +96,7 @@ fn process<V, F>(mut callback: F)
 {
     let mut config = None;
     let result = (|| {
-        config = Some(try!(Config::new(shell(true))));
+        config = Some(try!(Config::new(shell(Verbose))));
         let args: Vec<_> = try!(env::args_os().map(|s| {
             s.into_string().map_err(|s| {
                 human(format!("invalid unicode in argument: {:?}", s))
@@ -103,7 +104,7 @@ fn process<V, F>(mut callback: F)
         }).collect());
         callback(&args, config.as_ref().unwrap())
     })();
-    let mut verbose_shell = shell(true);
+    let mut verbose_shell = shell(Verbose);
     let mut shell = config.as_ref().map(|s| s.shell());
     let shell = shell.as_mut().map(|s| &mut **s).unwrap_or(&mut verbose_shell);
     process_executed(result, shell)
@@ -122,20 +123,20 @@ pub fn process_executed<T>(result: CliResult<Option<T>>, shell: &mut MultiShell)
     }
 }
 
-pub fn shell(verbose: bool) -> MultiShell {
+pub fn shell(verbosity: Verbosity) -> MultiShell {
     let tty = isatty(libc::STDERR_FILENO);
     let stderr = Box::new(io::stderr());
 
-    let config = ShellConfig { color: true, verbose: verbose, tty: tty };
+    let config = ShellConfig { color: true, verbosity: verbosity, tty: tty };
     let err = Shell::create(stderr, config);
 
     let tty = isatty(libc::STDOUT_FILENO);
     let stdout = Box::new(io::stdout());
 
-    let config = ShellConfig { color: true, verbose: verbose, tty: tty };
+    let config = ShellConfig { color: true, verbosity: verbosity, tty: tty };
     let out = Shell::create(stdout, config);
 
-    return MultiShell::new(out, err, verbose);
+    return MultiShell::new(out, err, verbosity);
 
     #[cfg(unix)]
     fn isatty(fd: libc::c_int) -> bool {
@@ -173,7 +174,7 @@ pub fn handle_error(err: CliError, shell: &mut MultiShell) {
     let fatal = exit_code != 0; // exit_code == 0 is non-fatal error
 
 
-    let hide = unknown && !shell.get_verbose();
+    let hide = unknown && shell.get_verbose() != Verbose;
     if hide {
         let _ = shell.err().say("An unknown error occurred", RED);
     } else {
@@ -195,12 +196,12 @@ fn handle_cause(mut cargo_err: &CargoError, shell: &mut MultiShell) -> bool {
             Some(cause) => cause,
             None => { err = cargo_err.cause(); break }
         };
-        if !verbose && !cargo_err.is_human() { return false }
+        if verbose != Verbose && !cargo_err.is_human() { return false }
         print(cargo_err.to_string(), shell);
     }
     loop {
         let cause = match err { Some(err) => err, None => return true };
-        if !verbose { return false }
+        if verbose != Verbose { return false }
         print(cause.to_string(), shell);
         err = cause.cause();
     }
index 9275ce380d7bc21b09f7e558aa9fa610987b5f58..d0f4945208bbaccd113ee301f35f6852f7e2c14f 100644 (file)
@@ -32,6 +32,44 @@ hello
     assert_that(&p.bin("foo"), existing_file());
 });
 
+test!(simple_quiet {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            fn main() { println!("hello"); }
+        "#);
+
+    assert_that(p.cargo_process("run").arg("-q"),
+                execs().with_status(0).with_stdout("\
+hello
+")
+    );
+});
+
+test!(simple_quiet_and_verbose {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            fn main() { println!("hello"); }
+        "#);
+
+    assert_that(p.cargo_process("run").arg("-q").arg("-v"),
+                execs().with_status(101).with_stderr("\
+cannot set both --verbose and --quiet
+")
+    );
+});
+
 test!(simple_with_args {
     let p = project("foo")
         .file("Cargo.toml", r#"
index a325165e81741d36de0b2b71dc95bb030be7ffea..630a74d09706b8e33fb024e2e09690084a77b115 100644 (file)
@@ -4,7 +4,8 @@ use std::sync::{Arc, Mutex};
 use term::{Terminal, TerminfoTerminal, color};
 use hamcrest::{assert_that};
 
-use cargo::core::shell::{Shell,ShellConfig};
+use cargo::core::shell::{Shell, ShellConfig};
+use cargo::core::shell::Verbosity::{Verbose, Quiet};
 
 use support::{Tap, shell_writes};
 
@@ -21,7 +22,7 @@ impl Write for Sink {
 }
 
 test!(non_tty {
-    let config = ShellConfig { color: true, verbose: true, tty: false };
+    let config = ShellConfig { color: true, verbosity: Verbose, tty: false };
     let a = Arc::new(Mutex::new(Vec::new()));
 
     Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
@@ -33,7 +34,7 @@ test!(non_tty {
 });
 
 test!(color_explicitly_disabled {
-    let config = ShellConfig { color: false, verbose: true, tty: true };
+    let config = ShellConfig { color: false, verbosity: Verbose, tty: true };
     let a = Arc::new(Mutex::new(Vec::new()));
 
     Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
@@ -47,7 +48,7 @@ test!(colored_shell {
     let term = TerminfoTerminal::new(Vec::new());
     if term.is_none() { return }
 
-    let config = ShellConfig { color: true, verbose: true, tty: true };
+    let config = ShellConfig { color: true, verbosity: Verbose, tty: true };
     let a = Arc::new(Mutex::new(Vec::new()));
 
     Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
@@ -59,6 +60,19 @@ test!(colored_shell {
                                             color::RED).unwrap()));
 });
 
+test!(quiet_shell {
+    let config = ShellConfig { color: true, verbosity: Quiet, tty: true };
+    let a = Arc::new(Mutex::new(Vec::new()));
+
+    Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
+        shell.say("Should be suppressed", color::BLACK).unwrap();
+    });
+
+    let buf = a.lock().unwrap().clone();
+    assert_that(&buf[..],
+                shell_writes(""));
+});
+
 fn colored_output(string: &str, color: color::Color) -> io::Result<String> {
     let mut term = TerminfoTerminal::new(Vec::new()).unwrap();
     try!(term.reset());